home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
sourcecode
/
various
/
ascii reader.amos
/
ascii reader.amosSourceCode
Wrap
AMOS Source Code
|
1994-01-01
|
9KB
|
316 lines
' ______________________________________________________________________
' | |
' | ASCII READER |
' | ~~~~~~~~~~~~ |
' | Created for AMOS Basic by Glenn N Babic, 1993 |
' | |
' | Use this program to read "ASCII/ASCII Reader.doc" |
' |______________________________________________________________________|
If Fast Free=False Then Close Editor : Close Workbench
Dir$="Df0:" : Break Off
Colour Back $DDD : Hide On
HGHT=30+Ntsc*6
WDTH=80
Screen Open 0,640,HGHT*8,2,Hires
Screen Display 0,,56,,(HGHT-1)*8
Curs Off : Palette $DDD,$0 : Pen 1 : Paper 0 : Cls
Screen Open 1,640,10,2,Hires
Screen Display 1,,44,,
Curs Off : Palette $DDD,$228 : Ink 0,1 : Cls 1
Screen To Back 1
Set Text 2
Text 10,7,"A S C I I R E A D E R" : Set Text 0
Text 212,,"- By Glenn N Babic - Written for AMOS Basic, 1993"
Screen 0
Set Paint 1
Global FILE_NAME$,FILE_LENGTH,HGHT,WDTH,FILE_END,DY
Global PAGE_START,PAGE_END,PCNT1
DY=Ntsc*24
HELP
Repeat
I$=Inkey$ : S=Scancode
If S=40 Then OPEN_FILE
If S=95 Then HELP
If FILE_LENGTH
If S=25 : SEND_TO_PRINTER : End If
P=PAGE_START
If S=76 or S=62 : LINE_UP : End If
If S=77 or S=30 : LINE_DOWN : End If
If S=63 : PAGE_UP : End If
If S=31 or S=64 : PAGE_DOWN : End If
If S=61 : PAGE_START=Start(6) : REFRESH : End If
If S=29 : BOTTOM : End If
If P<>PAGE_START : PERCENTAGE : End If
End If
Until S=69
Colour Back 0
Default
Edit
Procedure HELP
Ink 1,,1 : Bar 163,32+DY To 483,203+DY
Ink 0,1,1 : Bar 160,30+DY To 480,201+DY
Ink 1,0
Set Text 2 : Text 236,46+DY,"- H E L P M E N U -" : Set Text 0
Text 272,Ygr+16,"CONTROL KEYS"
Text 188,Ygr+12,"HELP...........View this menu"
Text 188,Ygr+9,"L..............Load an ASCII file"
Text 188,Ygr+9,"P..............Print file/page"
Text 188,Ygr+9,"ESC............Quit ASCII Reader"
Text 188,Ygr+9,"Home�..........View start of file"
Text 188,Ygr+9,"End�...........View end of file"
Text 188,Ygr+9,"Pg Up�.........Scroll up a page"
Text 188,Ygr+9,"Pg Dn�/SPACE...Scroll down a page"
Text 188,Ygr+9,"Up Arrow�......Up one line"
Text 188,Ygr+9,"Down Arrow�....Down one line"
Text 224,Ygr+13,"1 - Found on num. keypad"
Text 188,Ygr+8,"2 - Either num. keypad or cursors"
If FILE_LENGTH
Text 260,Ygr+15,"* Press a key *"
Else
Text 228,Ygr+15,"* Select Load or Quit *"
End If
If FILE_LENGTH Then Wait Key : Cls : REFRESH
End Proc
Procedure REFRESH
Home
LINE_START=PAGE_START
Repeat
RET=Hunt(LINE_START To Min(LINE_START+WDTH,FILE_END),Chr$(10))
If RET=False Then RET=Min(LINE_START+WDTH,FILE_END+1)
Cline
For I=LINE_START To RET-1 : Print Chr$(Peek(I)); : Next I
If RET>LINE_START and RET<LINE_START+WDTH Then Print
LINE_START=RET+1+(Peek(RET)<>10)
Inc LINES
Until LINES>HGHT-2 or LINE_START>FILE_END-2
PAGE_END=LINE_START
End Proc
Procedure OPEN_FILE
On Error Goto HANDLE_ERROR
Show On
MEM$="("+Str$(Chip Free+Fast Free+LAST_FILE_LENGTH)-" "+" bytes free)"
A$=Fsel$("ASCII/","","Choose ASCII file to view",MEM$)
Hide On
LAST_FILE_LENGTH=FILE_LENGTH
Open In 1,A$ : FL=Lof(1) : Close 1
ALERT["Loading...",False]
Erase 6
Reserve As Work 6,FL
Bload A$,6
FILE_NAME$=A$
Screen 1
If FILE_LENGTH=False
Set Text 6
Text -4,7," File:"+Space$(46)+"Size:"+Space$(14)+"Pos: "
Set Text 0
End If
FILE_LENGTH=FL
Text 52,7,Left$(FILE_NAME$,43)+Space$(43-Len(Left$(FILE_NAME$,43)))
B$=Left$(Str$(FL)-" "+" bytes",11)
Text 460,7,B$+Space$(11-Len(B$))
Text 604,7,"0% "
Screen 0
PAGE_START=Start(6)
FILE_END=Start(6)+Length(6)
1 Cls : REFRESH
If B$<>"" Then PCNT1=PAGE_END
PERCENTAGE
Pop Proc
HANDLE_ERROR:
If Errn=23 Then ALERT["No file chosen.",True]
If Errn=24 Then ALERT["Sorry - File too large!",True]
If Errn=81 Then ALERT["File not found!",True]
If Errn=94 Then ALERT["That file is corrupt!",True]
Resume 2
2 If FILE_LENGTH=False Then HELP Else 1
End Proc
Procedure ALERT[A$,F]
Ink 1 : Bar 298-Len(A$)*4,103+DY To 348+Len(A$)*4,133+DY
Ink 0,1,1 : Bar 295-Len(A$)*4,101+DY To 345+Len(A$)*4,131+DY
Ink 1,0
Set Text 2 : Text 320-Len(A$)*4,118+DY,A$ : Set Text 0
If F Then Bell 20 : Wait 60
End Proc
Procedure SEND_TO_PRINTER
Ink 1 : Bar 163,87+DY To 483,148+DY
Ink 0,1,1 : Bar 160,85+DY To 480,146+DY
Ink 1,0
Set Text 2 : Text 264,102+DY,"- PRINT FILE -" : Set Text 0
Text 200,115+DY,"How much do you wish to print?"
Reserve Zone 3
Text 208,133+DY,"ALL" : Text 284,,"THIS PAGE" : Text 396,,"CANCEL"
For I=1 To 3
Box 180+(I-1)*100,123+DY To 260+(I-1)*100,137+DY
Set Zone I,180+(I-1)*100,123+DY To 260+(I-1)*100,137+DY
Next I
Wait Vbl : Limit Mouse 208,141+DY To 368,202+DY
X Mouse=288 : Y Mouse=172+DY : Show On
Repeat : M=Mouse Zone : Until M and Mouse Click=1
Reserve Zone
Wait Vbl : Limit Mouse
If M=1 Then FIRST=Start(6) : LAST=FILE_END
If M=2 Then FIRST=PAGE_START : LAST=PAGE_END-1
If M<>3
Lprint ""; : Hide On
Ink 0,1,1 : Bar 160,85+DY To 480,146+DY
Ink 1,0 : Set Text 2 : Text 276,112+DY,"Printing..." : Set Text 0
Text 212,124+DY,"* Press any key to cancel *"
For I=FIRST To LAST
A$=Chr$(Peek(I))
If A$=Chr$(10) : A$=A$+Chr$(13) : End If
Lprint A$;
Exit If Inkey$<>""
Next I
End If
Hide On : Clear Key
Cls : REFRESH
End Proc
Procedure PAGE_UP
Repeat
LINE_UP
Inc LINES
Until LINES>HGHT-2 or PAGE_START<=Start(6)
End Proc
Procedure PAGE_DOWN
Repeat
LINE_DOWN
Inc LINES
Until LINES>HGHT-2 or PAGE_END>FILE_END-2
End Proc
Procedure LINE_UP
If PAGE_START<=Start(6) Then Bell 20 : Pop Proc
VARIABLES_UP
Print At(0,0);Chr$(30);
RET=Hunt(PAGE_START To Min(PAGE_START+WDTH,FILE_END),Chr$(10))
If RET=False Then RET=Min(PAGE_START+WDTH,FILE_END+1)
For I=PAGE_START To RET-1
Print Chr$(Peek(I));
Next I
If RET>PAGE_START and RET-PAGE_START<WDTH Then Print
'RET=Hunt(LINE_START To FILE_END,Chr$(10))
'If RET=0 Then RET=FILE_END+1
'For I=LINE_START To RET-1
' Print Chr$(Peek(I));
'Next I
'If RET<LINE_START+WDTH : Print : End If
Locate 0,HGHT-1 : Cline
End Proc
Procedure LINE_DOWN
If PAGE_END>FILE_END-2 Then Bell 20 : Pop Proc
'PAGE_START down one line...
RET=Hunt(PAGE_START To Min(PAGE_START+WDTH,FILE_END),Chr$(10))
If RET=False Then RET=Min(PAGE_START+WDTH,FILE_END+1)
PAGE_START=RET+1+(Peek(RET)<>10)
RET=Hunt(PAGE_END To Min(PAGE_END+WDTH,FILE_END),Chr$(10))
If RET=False Then RET=Min(PAGE_END+WDTH,FILE_END+1)
For I=PAGE_END To RET-1
Print Chr$(Peek(I));
Next I
If RET>PAGE_END and RET-PAGE_END<WDTH Then Print
'PAGE_END down one line...
PAGE_END=RET+1+(Peek(RET)<>10)
End Proc
Procedure PERCENTAGE
If FILE_END-PCNT1<=0
PERCENT=100
Else
PERCENT=((PAGE_END-PCNT1+1)*100)/(FILE_END-PCNT1)
End If
Screen 1
Text 604,7,Str$(PERCENT)-" "+"% "
Screen 0
End Proc
Procedure BOTTOM
PAGE_START=FILE_END-1
For I=1 To HGHT-1
VARIABLES_UP
Next I
REFRESH
End Proc
Procedure VARIABLES_UP
'PAGE_START/END up one line...
For J=0 To 1
If J=0 Then LINE_START=PAGE_START Else LINE_START=PAGE_END
RET=Max(LINE_START-WDTH-3,Start(6)-1)
Repeat
LAST_RET=RET+1
RET=Hunt(LAST_RET To LINE_START-1,Chr$(10))
Until RET=False
If LAST_RET=Max(LINE_START-WDTH-2,Start(6))
For I=LINE_START-2 To Start(6)-1 Step -1
If Peek(I)=10 or I=Start(6)-1
LINE_START=(LINE_START-2-I)/WDTH*WDTH+1+I : Exit
End If
Next I
Else
LINE_START=LAST_RET
End If
If J=0 Then PAGE_START=LINE_START Else PAGE_END=LINE_START
Next J
'Do
' RET=Hunt(LAST_RET To PAGE_START-1,Chr$(10))
' If RET=0 Then PAGE_START=LAST_RET : Exit
' LAST_RET=RET+1
'Loop
'
''PAGE_END up one line...
'LAST_RET=Max(PAGE_END-WDTH-1,Start(6))
'Do
' RET=Hunt(LAST_RET To PAGE_END-1,Chr$(10))
' If RET=0 Then PAGE_END=LAST_RET : Exit
' LAST_RET=RET+1
'Loop
End Proc